// 实时监听插件
(function ($, window, undefined) {
    var elems = $([]),
        jq_resize = $.resize = $.extend($.resize, {}),
        timeout_id,
        str_setTimeout = 'setTimeout',
        str_resize = 'resize',
        str_data = str_resize + '-special-event',
        str_delay = 'delay',
        str_throttle = 'throttleWindow';
    jq_resize[str_delay] = 250;
    jq_resize[str_throttle] = true;
    $.event.special[str_resize] = {
        setup: function () {
            if (!jq_resize[str_throttle] && this[str_setTimeout]) {
                return false;
            }
            var elem = $(this);
            elems = elems.add(elem);
            $.data(this, str_data, {
                w: elem.width(),
                h: elem.height()
            });
            if (elems.length === 1) {
                loopy();
            }
        },
        teardown: function () {
            if (!jq_resize[str_throttle] && this[str_setTimeout]) {
                return false;
            }
            var elem = $(this);
            elems = elems.not(elem);
            elem.removeData(str_data);
            if (!elems.length) {
                clearTimeout(timeout_id);
            }
        },
        add: function (handleObj) {
            if (!jq_resize[str_throttle] && this[str_setTimeout]) {
                return false;
            }
            var old_handler;

            function new_handler(e, w, h) {
                var elem = $(this),
                    data = $.data(this, str_data);
                data.w = w !== undefined ? w : elem.width();
                data.h = h !== undefined ? h : elem.height();
                old_handler.apply(this, arguments);
            }

            if ($.isFunction(handleObj)) {
                old_handler = handleObj;
                return new_handler;
            } else {
                old_handler = handleObj.handler;
                handleObj.handler = new_handler;
            }
        }
    };

    function loopy() {
        timeout_id = window[str_setTimeout](function () {
            elems.each(function () {
                var elem = $(this),
                    width = elem.width(),
                    height = elem.height(),
                    data = $.data(this, str_data);
                if (width !== data.w || height !== data.h) {
                    elem.trigger(str_resize, [data.w = width, data.h = height]);
                }
            });
            loopy();
        }, jq_resize[str_delay]);
    }
})(jQuery, this);
// 实时监听插件 end

$(document).ready(function () {

    var lw = $(".elst-select-mini .el-input__suffix span .el-select").parent().parent().parent().children("div.el-input-group__prepend");
    var arrLw = new Array();
    for (i = 0; i < lw.length; i++) {
        var n = 'lw' + i;
        arrLw.push(n);
        lw.eq(i).attr("id", arrLw[i]);
    }
    var cw = $(".elst-select-mini .el-input__suffix span .el-select").parent().parent().parent().parent().parent().children("div.el-form-item__content");
    var arrCw = new Array();
    for (i = 0; i < cw.length; i++) {
        var n = 'cw' + i;
        arrCw.push(n);
        cw.eq(i).attr("id", arrCw[i]);
    }
    var pw = $(".elst-select-mini .el-input__suffix span .el-select");
    var arrPw = new Array();
    for (i = 0; i < pw.length; i++) {
        var n = 'pw' + i;
        arrPw.push(n);
        pw.eq(i).attr("id", arrPw[i]);
        // console.log(arrLw[i] + ":" + $("#" + arrLw[i]).width())
        // console.log(arrCw[i] + ":" + $("#" + arrCw[i]).width());
        $("#" + arrPw[i]).width($("#" + arrCw[i]).width() - $("#" + arrLw[i]).width() - 48)
        // console.log(arrPw[i] + ":" + $("#" + arrPw[i]).width());
    }


    var tlw = $(".vue-treeselect");
    var arrTlw = new Array();
    for (i = 0; i < tlw.length; i++) {
        var n = 'tlw' + i;
        arrTlw.push(n);
        tlw.eq(i).attr("id", arrTlw[i]);
    }
    var tpw = $(".vue-treeselect").parent().parent().parent().children("div.el-input-group__prepend");
    var arrTpw = new Array();
    for (i = 0; i < tpw.length; i++) {
        var n = 'tpw' + i;
        arrTpw.push(n);
        tpw.eq(i).attr("id", arrTpw[i]);
    }
    var tcw = $(".vue-treeselect").parent().parent().parent().parent().parent().children("div.el-form-item__content");
    var arrTcw = new Array();
    for (i = 0; i < tpw.length; i++) {
        var n = 'tcw' + i;
        arrTcw.push(n);
        tcw.eq(i).attr("id", arrTcw[i]);
        $("#" + arrTlw[i]).width($("#" + arrTcw[i]).width() - $("#" + arrTpw[i]).width() - 48)
    }



    var dpw = $(".elst-select-mini .el-date-editor--datetime");
    var arrDpw = new Array();
    for (i = 0; i < dpw.length; i++) {
        var n = 'dpw' + i;
        arrDpw.push(n);
        dpw.eq(i).attr("id", arrDpw[i]);
    }
    var diw = $(".elst-select-mini .el-date-editor--datetime").parent().parent().parent().children("div.el-input-group__prepend");
    var arrDiw = new Array();
    for (i = 0; i < diw.length; i++) {
        var n = 'diw' + i;
        arrDiw.push(n);
        diw.eq(i).attr("id", arrDiw[i]);
        // $("#" + arrDpw[i]).width($("#" + arrDiw[i]).width() + 40)
    }
    var dcw = $(".elst-select-mini .el-date-editor--datetime").parent().parent().parent().parent().parent().children("div.elst-select-mini");
    var arrDcw = new Array();
    for (i = 0; i < dcw.length; i++) {
        var n = 'dcw' + i;
        arrDcw.push(n);
        dcw.eq(i).attr("id", arrDcw[i]);
        $("#" + arrDpw[i]).width($("#" + arrDcw[i]).width() - $("#" + arrDiw[i]).width() - 48)
    }



    //针对el-date-editor--date
    var dpwn = $(".el-date-editor--date");
    var arrDpwn = new Array();
    for (i = 0; i < dpwn.length; i++) {
        var n = 'dpwn' + i;
        arrDpwn.push(n);
        dpwn.eq(i).attr("id", arrDpwn[i]);
    }
    var diwn = $(".el-date-editor--date").parent().parent().parent().children("div.el-input-group__prepend");
    var arrDiwn = new Array();
    for (i = 0; i < diwn.length; i++) {
        var n = 'diwn' + i;
        arrDiwn.push(n);
        diwn.eq(i).attr("id", arrDiwn[i]);
    }
    var dcwn = $(".el-date-editor--date").parent().parent().parent().children("input.el-input__inner");
    var arrDcwn = new Array();
    for (i = 0; i < dcwn.length; i++) {
        var n = 'dcwn' + i;
        arrDcwn.push(n);
        dcwn.eq(i).attr("id", arrDcwn[i]);
        $("#" + arrDpwn[i]).width(($("#" + arrDcwn[i]).width() + 40))
    }

    var dpwn_input = $(".el-date-editor--date").children("input.el-input__inner");
    for (var i = 0; i < dpwn_input.length; i++) {
        dpwn_input.eq(i).css({
            "padding-left": "26px",
            "padding-right": "0px"
        });
    }


    //针对el-date-editor--date
    var dYpwn = $(".el-date-editor--year");
    var arrDYpwn = new Array();
    for (i = 0; i < dYpwn.length; i++) {
        var n = 'dYpwn' + i;
        arrDYpwn.push(n);
        dYpwn.eq(i).attr("id", arrDYpwn[i]);
    }
    var dYiwn = $(".el-date-editor--year").parent().parent().parent().children("div.el-input-group__prepend");
    var arrDYiwn = new Array();
    for (i = 0; i < dYiwn.length; i++) {
        var n = 'dYiwn' + i;
        arrDYiwn.push(n);
        dYiwn.eq(i).attr("id", arrDYiwn[i]);
    }
    var dYcwn = $(".el-date-editor--year").parent().parent().parent().children("input.el-input__inner");
    var arrDYcwn = new Array();
    for (i = 0; i < dYcwn.length; i++) {
        var n = 'dYcwn' + i;
        arrDYcwn.push(n);
        dYcwn.eq(i).attr("id", arrDYcwn[i]);
        $("#" + arrDYpwn[i]).width(($("#" + arrDYcwn[i]).width() + 40))
    }

    var dYpwn_input = $(".el-date-editor--year").children("input.el-input__inner");
    for (var i = 0; i < dYpwn_input.length; i++) {
        dYpwn_input.eq(i).css({
            "padding-left": "26px",
            "padding-right": "0px"
        });
    }


    //针对el-date-editor--date
    var dMpwn = $(".el-date-editor--month");
    var arrDMpwn = new Array();
    for (i = 0; i < dMpwn.length; i++) {
        var n = 'dMpwn' + i;
        arrDMpwn.push(n);
        dMpwn.eq(i).attr("id", arrDMpwn[i]);
    }
    var dMiwn = $(".el-date-editor--month").parent().parent().parent().children("div.el-input-group__prepend");
    var arrDMiwn = new Array();
    for (i = 0; i < dMiwn.length; i++) {
        var n = 'dMiwn' + i;
        arrDMiwn.push(n);
        dMiwn.eq(i).attr("id", arrDMiwn[i]);
    }
    var dMcwn = $(".el-date-editor--month").parent().parent().parent().children("input.el-input__inner");
    var arrDMcwn = new Array();
    for (i = 0; i < dMcwn.length; i++) {
        var n = 'dYcwn' + i;
        arrDMcwn.push(n);
        dMcwn.eq(i).attr("id", arrDMcwn[i]);
        $("#" + arrDMpwn[i]).width(($("#" + arrDMcwn[i]).width() + 40))
    }

    var dMpwn_input = $(".el-date-editor--month").children("input.el-input__inner");
    for (var i = 0; i < dMpwn_input.length; i++) {
        dMpwn_input.eq(i).css({
            "padding-left": "26px",
            "padding-right": "0px"
        });
    }



    (function ($) {
        $(window).load(function () {
            //   左侧菜单高度限制
            var appHeight = (document.documentElement.clientHeight - 240) + 'px'
            $(".tree_lay .el-tree").css('height', appHeight);
            //$.mCustomScrollbar.defaults.axis = "y";
            //$(".tree_lay div").mCustomScrollbar({
            //    theme: "dark"
            //});
            //$(".mCSB_draggerContainer").css('display', 'none');
            $(".tree_lay .el-tree").mouseenter(function () {
                $(".tree_lay .el-tree").css('overflow-y', 'scroll');
            });
            $(".tree_lay .el-tree").mouseleave(function () {
                $(".tree_lay .el-tree").css('overflow-y', 'hidden');
            });
            // $("#mCSB_1_container").mouseenter(function () {
            //     var needTitle = $("#mCSB_1_container div div li .el-submenu__title")
            //     var arrNeedTitle = new Array();
            //     for (i = 0; i < needTitle.length; i++) {
            //         var n = 'needTitle' + i;
            //         arrNeedTitle.push(n);
            //         needTitle.eq(i).attr("id", arrNeedTitle[i]);
            //     }
            // });
        });
        // $("aside").mouseenter(function () {
        //     // alert(1)
        //     $("#mCSB_1_scrollbar_vertical").css("display", "block");
        //     $("#mCSB_1_scrollbar_horizontal").css("display", "block");
        // });
        // $("aside").mouseleave(function () {
        //     $("#mCSB_1_scrollbar_vertical").css("display", "none");
        //     $("#mCSB_1_scrollbar_horizontal").css("display", "none");
        // });
    })(jQuery);

    //table最后两个居中显示
    // var tableThLast = ($(".el-table thead tr th").length - 1) / 2
    // var tableThLastUp = ($(".el-table thead tr th").length - 1) / 2 - 1
    // $(".el-table_1_column_" + tableThLast).css('text-align', 'center')
    // $(".el-table_1_column_" + tableThLastUp).css('text-align', 'center')
    for (i = 0; i < $(".el-table thead tr th").length; i++) {
        $(".has-gutter .el-table_1_column_" + i).css('text-align', 'center')
    }




    $("body").bind('resize', function () {
        for (i = 0; i < pw.length; i++) {
            var n = 'pw' + i;
            arrPw.push(n);
            pw.eq(i).attr("id", arrPw[i]);
            // console.log(arrLw[i] + ":" + $("#" + arrLw[i]).width())
            // console.log(arrCw[i] + ":" + $("#" + arrCw[i]).width());
            $("#" + arrPw[i]).width($("#" + arrCw[i]).width() - $("#" + arrLw[i]).width() - 48)
            // console.log(arrPw[i] + ":" + $("#" + arrPw[i]).width());
        }
        for (i = 0; i < tpw.length; i++) {
            var n = 'tcw' + i;
            arrTcw.push(n);
            tcw.eq(i).attr("id", arrTcw[i]);
            $("#" + arrTlw[i]).width($("#" + arrTcw[i]).width() - $("#" + arrTpw[i]).width() - 48)
        }
        for (i = 0; i < dcw.length; i++) {
            var n = 'dcw' + i;
            arrDcw.push(n);
            dcw.eq(i).attr("id", arrDcw[i]);
            $("#" + arrDpw[i]).width($("#" + arrDcw[i]).width() - $("#" + arrDiw[i]).width() - 48)
        }
        //针对el-date-editor--date
        for (i = 0; i < dcwn.length; i++) {
            var n = 'dcwn' + i;
            arrDcwn.push(n);
            dcwn.eq(i).attr("id", arrDcwn[i]);
            $("#" + arrDpwn[i]).width(($("#" + arrDcwn[i]).width() + 40))
        }
        for (i = 0; i < dYcwn.length; i++) {
            var n = 'dYcwn' + i;
            arrDYcwn.push(n);
            dYcwn.eq(i).attr("id", arrDYcwn[i]);
            $("#" + arrDYpwn[i]).width(($("#" + arrDYcwn[i]).width() + 40))
        }
        for (i = 0; i < dMcwn.length; i++) {
            var n = 'dYcwn' + i;
            arrDMcwn.push(n);
            dMcwn.eq(i).attr("id", arrDMcwn[i]);
            $("#" + arrDMpwn[i]).width(($("#" + arrDMcwn[i]).width() + 40))
        }
        var appHeight = (document.documentElement.clientHeight - 110) + 'px'
        $(".tree_lay .el-tree").css('height', appHeight);
    });

    // 解决表格展开不出滚动条bug
    $(".ele_expand tbody").bind('resize', function () {
        let height = ListItem.tableHeight - 45
        let height_2 = $('.el-table tbody').height()
        if (height_2 > height) {
            $('.el-table').css('height', height + 46)
        } else {
            $('.el-table').css('height', height + 45)
        }
    });

});